package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.TrainingCadetClassicsExperience;
import com.ruoyi.system.domain.TrainingCadetClassicsExperienceCount;
import com.ruoyi.system.mapper.TrainingCadetClassicsExperienceMapper;
import com.ruoyi.system.service.ITrainingCadetClassicsExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学习典籍体会Service业务层处理
 *
 * @author dp
 * @date 2023-11-27
 */
@Service
public class TrainingCadetClassicsExperienceServiceImpl implements ITrainingCadetClassicsExperienceService {
    @Autowired
    private TrainingCadetClassicsExperienceMapper trainingCadetClassicsExperienceMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询学习典籍体会
     *
     * @param experienceId 学习典籍体会主键
     * @return 学习典籍体会
     */
    @Override
    public TrainingCadetClassicsExperience selectTrainingCadetClassicsExperienceByExperienceId(Long experienceId) {
        return trainingCadetClassicsExperienceMapper.selectTrainingCadetClassicsExperienceByExperienceId(experienceId);
    }

    /**
     * 查询学习典籍体会列表
     *
     * @param trainingCadetClassicsExperience 学习典籍体会
     * @return 学习典籍体会
     */
    @Override
    public List<TrainingCadetClassicsExperience> selectTrainingCadetClassicsExperienceList(TrainingCadetClassicsExperience trainingCadetClassicsExperience) {
        return trainingCadetClassicsExperienceMapper.selectTrainingCadetClassicsExperienceList(trainingCadetClassicsExperience);
    }

    /**
     * 查询学习典籍体会合计列表
     * @param submitBegin
     * @param submitEnd
     * @param baseId
     * @param experienceStatus
     * @param cadetId
     * @param cadetName
     * @return
     */
    @Override
    public List<TrainingCadetClassicsExperienceCount> selectTrainingCadetClassicsExperienceCount(
            String submitBegin, String submitEnd, String baseId, String experienceStatus, Long cadetId, String cadetName) {
        return trainingCadetClassicsExperienceMapper.selectTrainingCadetClassicsExperienceCount(
                submitBegin, submitEnd, baseId, experienceStatus, cadetId, cadetName);
    }

    @Override
    public List<TrainingCadetClassicsExperience> getExperienceList(String submitBegin, String submitEnd, String baseId, String cadetId, String experienceStatus) {
        return trainingCadetClassicsExperienceMapper.getExperienceList(submitBegin, submitEnd, baseId, cadetId, experienceStatus);
    }

    /**
     * 新增学习典籍体会
     *
     * @param trainingCadetClassicsExperience 学习典籍体会
     * @return 结果
     */
    @Override
    public int insertTrainingCadetClassicsExperience(TrainingCadetClassicsExperience trainingCadetClassicsExperience) {
        trainingCadetClassicsExperience.setCreateTime(DateUtils.getNowDate());
        if (trainingCadetClassicsExperience.getMentorId() != null && trainingCadetClassicsExperience.getMentorId().isEmpty()) {
            trainingCadetClassicsExperience.setMentorId(null);
        }
        return trainingCadetClassicsExperienceMapper.insertTrainingCadetClassicsExperience(trainingCadetClassicsExperience);
    }

    /**
     * 修改学习典籍体会
     *
     * @param trainingCadetClassicsExperience 学习典籍体会
     * @return 结果
     */
    @Override
    public int updateTrainingCadetClassicsExperience(TrainingCadetClassicsExperience trainingCadetClassicsExperience) {
        if (trainingCadetClassicsExperience.getMentorId() != null && trainingCadetClassicsExperience.getMentorId().isEmpty()) {
            trainingCadetClassicsExperience.setMentorId(null);
        }
        return trainingCadetClassicsExperienceMapper.updateTrainingCadetClassicsExperience(trainingCadetClassicsExperience);
    }

    /**
     * 批量删除学习典籍体会
     *
     * @param experienceIds 需要删除的学习典籍体会主键
     * @return 结果
     */
    @Override
    public int deleteTrainingCadetClassicsExperienceByExperienceIds(Long[] experienceIds) {
        return trainingCadetClassicsExperienceMapper.deleteTrainingCadetClassicsExperienceByExperienceIds(experienceIds);
    }

    /**
     * 删除学习典籍体会信息
     *
     * @param experienceId 学习典籍体会主键
     * @return 结果
     */
    @Override
    public int deleteTrainingCadetClassicsExperienceByExperienceId(Long experienceId) {
        return trainingCadetClassicsExperienceMapper.deleteTrainingCadetClassicsExperienceByExperienceId(experienceId);
    }

    /**
     * 实体数据补全
     *
     * @param trainingCadetClassicsExperience 实体
     * @param userId                          用户id
     * @param crateType                       创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(TrainingCadetClassicsExperience trainingCadetClassicsExperience, Long userId, Integer crateType) {
        //主键
        if (trainingCadetClassicsExperience.getExperienceId() == null || "".equals(trainingCadetClassicsExperience.getExperienceId())) {
            trainingCadetClassicsExperience.setExperienceId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (trainingCadetClassicsExperience.getCreateBy() == null) {
                trainingCadetClassicsExperience.setCreateBy(userId.toString());
            }
            if (trainingCadetClassicsExperience.getCreateTime() == null) {
                trainingCadetClassicsExperience.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (trainingCadetClassicsExperience.getModifyBy() == null) {
            trainingCadetClassicsExperience.setModifyBy(userId);
        }
        //修改时间
        if (trainingCadetClassicsExperience.getModifyTime() == null) {
            trainingCadetClassicsExperience.setModifyTime(DateUtils.getNowDate());
        }
    }
}
